import logging
from flask import Flask, request, jsonify 

logger = logging.getLogger(__name__)

def configure_logging():
    logging.basicConfig(filename='error.log', level=logging.DEBUG) #logging

def create_app():
    app = Flask(__name__)

    @app.route('/webhook', methods=['POST'])
    def handle_webhook():
        try:
            webhook_event_data = request.json
        except Exception as e:
            logger.error("Error handling webhook: %s", e)
            return "Error", 400
    
        logger.info("Received webhook data: %s", webhook_event_data)      
        return jsonify({"message": "Webhook received successfully"}), 200
    
    return app

if __name__ == '__main__':
    configure_logging()
    app = create_app()
    app.run(host='0.0.0.0', port=8000, debug=True, use_reloader=False)